%%%-------------------------------------------------------------------
%%% @author admin
%%% @copyright (C) 2021, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 31. 十二月 2021 16:34
%%%-------------------------------------------------------------------
-module(player).
-author("admin").
-include("player.hrl").
-include("db_load.hrl").
%% API
-export([
    init/2,
    born/1,
    save/1
]).


init(UUid, SPid) ->
    %% 这里读取数据库从数据库拿角色数据
     case db_load:load(?TABLE_PLAYER, UUid) of
         {ok, Player0} ->
             Player1 = Player0#player{spid = SPid},
             %% 这里读取功能数据库并且组装
    
             PlayerFinish = Player1#{},
    
             %% 这里可以做一些初始化操作
    
             PlayerFinish;
         Err -> Err
     end.

born(Args) ->
    #{
        name := Name
    } = Args,
    
    #player{
        uuid = pub_data:player_id_inc(),
        name = Name
    }.

save(Player = #player{uuid = UUid}) ->
    db_load:save(?TABLE_PLAYER, UUid, Player),
    ok.